<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
String path = request.getContextPath();
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加推文</title>
<link rel="stylesheet" href="<%=path%>/resource/iKindEditor/editor/plugins/code/prettify.css" />
<link rel="stylesheet" href="<%=path%>/resource/iKindEditor/editor/themes/default/default.css" />

<script charset="utf-8" src="<%=path%>/resource/js/jquery/jquery-1.8.2.js"></script>
<script charset="utf-8" src="<%=path%>/resource/iKindEditor/editor/kindeditor.js"></script>
<script charset="utf-8" src="<%=path%>/resource/iKindEditor/editor/lang/zh_CN.js"></script>
<script charset="utf-8" src="<%=path%>/resource/iKindEditor/editor/plugins/code/prettify.js"></script>
<script charset="utf-8" src="<%=path%>/resource/js/articleEditor.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#submitButton").click(doSubmitTweet);
	$("#title").focus(function() {
		var $this = $(this);
		/* $this.addClass("title_focus"); */
		if ($this.val() == this.defaultValue)
			$this.val("");
	}).blur(function() {
		var $this = $(this);
		$this.removeClass("title_focus");
		if ("" == jQuery.trim($this.val())) {
			$this.val(this.defaultValue);
		}
	}).mouseover(function(){
		var $this = $(this);
		if (!$this.hasClass("title_focus")) {
			$this.addClass("title_focus");
		}
	}).mouseout(function(){
		var $this = $(this);
		if ($this.val() == this.defaultValue) {
			$this.removeClass("title_focus");
		}
	});
});

function doSubmitTweet() {
	articleEditor_inputEditor.sync(); // 将编辑框中的内容同步到textarea编辑框中来
	//var content = articleEditor_inputEditor.text().replace(new RegExp("<\\s*img\\s+([^>]*)>", 'g'), "").replace(new RegExp("<\\s*embed\\s+([^>]*)>", 'g'), "");
	var content = articleEditor_inputEditor.text();
	var title = $("#title").val();
	if (content && "" != content && jQuery.trim(content) != "" && jQuery.trim(title) != "") {
		if (checkStr(title)) {
			alert("请规范化数据,不能加入<script>等脚本语言");
		} else {
			$("#tweetForm").submit();
		}
	} else {
		alert("请先完善数据");
	}
}

function checkStr(str) {
	var reg = new RegExp("<.*?script[^>]*?>.*?(<\/.*?script.*?>)*","ig");
	
	return reg.test(str);
}
</script>
<style type="text/css">
body{
color: #333333;
font-family: "微软雅黑"
}

.title_box {
width: 800px; height: 32px; line-height: 32px;
}

.title_box .title {
display: block; 
width: 800px; 
height: 32px; 
line-height: 32px; 
text-align: center;
border-style: none; 
background: #EDEDED;
border: 1px solid #CCCCCC; 
border-bottom: 1px solid #F0F0EE;
border-top: none; 
color: #777777;
}
.title_box .title_focus {
background: #FDEDEF;
color: #333333;
}
</style>
</head>
<body>
	<div style="width: 800px; min-height: 600px; height: auto!important; height: 600px; margin: auto; margin-top: 20px;">
		<div style="width: 800px; height: 40px; line-height: 40px; background: #F0F0EE; text-align: center; border: 1px solid #CCCCCC;">发布推文</div>
		<form action="<%=path %>/ad/admin/doPublishTweet" method="post" id="tweetForm">
			<div class="title_box">
				<input type="text" name="title" class="title" id="title" value="请在这里输入标题" maxlength="50">
			</div>
			<div class="content_box">
				<textarea id="inputTextArea" name="content" style="display: bolck; width:800px; height:600px;"></textarea>
			</div>
			<div>
				<input type="button" value="发布" id="submitButton" />
			</div>
		</form>
	</div>
</body>
</html>